//
//  LGSportsSendRecordCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/8/7.
//  运动方案-发放记录

#import "LGSportsSendRecordCell.h"

@interface LGSportsSendRecordCell()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIImageView *picView;
/**   */
@property (nonatomic , strong)UILabel *nameLabel;
/**   */
@property (nonatomic , strong)UILabel *ageLabel;
/**   */
@property (nonatomic , strong)UIImageView *vipView;
/**   */
@property (nonatomic , strong)UILabel *numberLabel;
/**   */
@property (nonatomic , strong)UILabel *timeLabel;
/**   */
@property (nonatomic , strong)UIView *lineView;
/**   */
@property (nonatomic , strong)UIButton *backBtn;
/**   */
@property (nonatomic , strong)NSDictionary *vipWidth;

@end

@implementation LGSportsSendRecordCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.vipWidth = @{@"1":@(16),@"2":@(32),@"3":@(48),@"4":@(64)};
        [self createSubView];
    }
    return  self;
}

-(void)setIndexPath:(NSIndexPath *)indexPath{
    _indexPath = indexPath;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    UIImage *placeHolder = [dataDic[@"gender"] isEqualToString:@"女"]?defaultPatientWomen:defaultPatientMan;
    [self.picView sd_setImageWithURL:[NSURL URLWithString:LGNSString(dataDic[@"avatar_url"])] placeholderImage:placeHolder];
    self.nameLabel.text = LGNSString(dataDic[@"patient_name"]);
    self.ageLabel.text = [NSString stringWithFormat:@"%@ %@岁",dataDic[@"gender"],dataDic[@"age"]];
    [self.vipView sd_setImageWithURL:[NSURL URLWithString:LGNSString(dataDic[@"vip_icon"])]];
    self.numberLabel.text = LGNSString(dataDic[@"hospital_bano"]);
    self.timeLabel.text = LGNSString(dataDic[@"create_time"]);
    self.lineView.hidden = ([dataDic[@"can_revoke"] integerValue] == 1 || [dataDic[@"is_deleted"] integerValue] == 1)?NO:YES;
    self.backBtn.hidden = ([dataDic[@"can_revoke"] integerValue] == 1 || [dataDic[@"is_deleted"] integerValue] == 1)?NO:YES;
    CGFloat height = ([dataDic[@"can_revoke"] integerValue] == 1 || [dataDic[@"is_deleted"] integerValue] == 1)?viewPix(110):viewPix(70);
    [self.baseView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(height));
    }];
    self.backBtn.userInteractionEnabled = ([dataDic[@"is_deleted"] integerValue] == 1)?NO:YES;
    self.backBtn.selected = ([dataDic[@"is_deleted"] integerValue] == 1)?NO:YES;
    NSString *boaderColor = ([dataDic[@"is_deleted"] integerValue] == 1)?@"#999999":@"#3291FF";
    self.backBtn.layer.borderColor = [UIColor colorWithString:boaderColor].CGColor;
}

//撤回
-(void)backBtnAction{
    if(self.delegate && [self.delegate respondsToSelector:@selector(revocationSportsPlan:)]){
        [self.delegate revocationSportsPlan:self.dataDic];
    }
    
    if(self.delegate && [self.delegate respondsToSelector:@selector(revocationSportsPlanIndexPath:)]){
        [self.delegate revocationSportsPlanIndexPath:self.indexPath];
    }
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.clipsToBounds = YES;
    self.contentView.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
    [self.contentView addSubview:self.baseView];
    [self.baseView addSubview:self.picView];
    [self.baseView addSubview:self.picView];
    [self.baseView addSubview:self.nameLabel];
    [self.baseView addSubview:self.ageLabel];
    [self.baseView addSubview:self.vipView];
    [self.baseView addSubview:self.numberLabel];
    [self.baseView addSubview:self.timeLabel];
    [self.baseView addSubview:self.lineView];
    [self.baseView addSubview:self.backBtn];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(viewPix(12));
        make.bottom.equalTo(self.contentView).offset(-viewPix(4));
        make.left.equalTo(self.contentView).offset(viewPix(16));
        make.right.equalTo(self.contentView).offset(-viewPix(16));
        make.height.equalTo(@(viewPix(70)));
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.baseView).offset(viewPix(13));
        make.left.equalTo(self.picView.mas_right).offset(viewPix(8));
    }];
    [self.ageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right).offset(viewPix(6));
        make.centerY.equalTo(self.nameLabel);
    }];
    [self.vipView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.ageLabel.mas_right).offset(viewPix(6));
        make.centerY.equalTo(self.ageLabel);
        make.width.height.equalTo(@(viewPix(16)));
    }];
    [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(20));
        make.centerY.equalTo(self.nameLabel);
    }];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLabel.mas_bottom).offset(viewPix(5));
        make.left.equalTo(self.nameLabel);
        make.right.equalTo(self.numberLabel);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.picView.mas_bottom).offset(viewPix(10));
        make.left.equalTo(self.picView);
        make.right.equalTo(self.numberLabel);
        make.height.equalTo(@(0.5));
    }];
    [self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(20));
        make.top.equalTo(self.lineView.mas_bottom).offset(viewPix(8));
        make.width.equalTo(@(viewPix(72)));
        make.height.equalTo(@(viewPix(24)));
    }];
    
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}

-(UIImageView *)picView{
    if(!_picView){
        _picView = [[UIImageView alloc]initWithFrame:CGRectMake(viewPix(12), viewPix(12), viewPix(46), viewPix(46))];
        _picView.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
        _picView.cornerRidus = 8;
    }
    return _picView;
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _nameLabel;
}

-(UILabel *)ageLabel{
    if(!_ageLabel){
        _ageLabel = [UILabel lableWithText:@"" colorString:@"#999999" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _ageLabel;
}

-(UIImageView *)vipView{
    if(!_vipView){
        _vipView = [[UIImageView alloc]init];
    }
    return _vipView;
}

-(UILabel *)numberLabel{
    if(!_numberLabel){
        _numberLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(13) textAlignment:NSTextAlignmentRight lines:1];
    }
    return _numberLabel;
}

-(UILabel *)timeLabel{
    if(!_timeLabel){
        _timeLabel = [UILabel lableWithText:@"" colorString:@"#999999" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _timeLabel;
}

-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = [UIColor colorWithString:@"#F2F2F2"];
        _lineView.hidden = YES;
    }
    return _lineView;
}

-(UIButton *)backBtn{
    if(!_backBtn){
        _backBtn = [UIButton buttonWithTitle:@"已撤回" titleFont:LGFont(14) normalColor:@"#999999" selectColor:@"#3291FF"];
        [_backBtn setTitle:@"撤回" forState:UIControlStateSelected];
        _backBtn.layer.borderColor = [UIColor colorWithString:@"#999999"].CGColor;
        _backBtn.layer.borderWidth = 1;
        _backBtn.cornerRidus = viewPix(12);
        _backBtn.hidden = YES;
        [_backBtn addTarget:self action:@selector(backBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _backBtn;
}




- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
